#ifndef _POOL_H_
#define _POOL_H_

#include <iostream>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/thread.hpp>

class Pool : public boost::noncopyable
{
private:
	typedef boost::shared_ptr<boost::asio::io_service> io_service_sptr;
	typedef boost::shared_ptr<boost::asio::io_service::work> work_sptr;
	typedef boost::shared_ptr<boost::thread> thread_sptr;

	boost::mutex _mtx;
	std::vector<io_service_sptr> _io_service;
	std::vector<work_sptr> _work;
	std::vector<thread_sptr> _threads;
	std::size_t _next_io_service_index;

	io_service_sptr _control_io_service;
	work_sptr _control_work;
	thread_sptr _control_thread;
	
public:
	explicit Pool(std::size_t pool_size);
	void Start();
	void Join();
	void Stop();
	boost::asio::io_service & GetIoService();
	boost::asio::io_service & GetIoService(int &id);
	boost::asio::io_service & GetControlService();
};

#endif
